package com.bird.component.lang.util.paramcheck.inter

import cn.hutool.core.util.StrUtil
import java.util.*

interface ICheckModel {

    val checkBeans: MutableList<ICheckBean>

    fun getStartStr(): String {
        return ""
    }

    fun getEndStr(): String {
        return System.lineSeparator()
    }
    /**
     * 进行校验
     */
    fun check(): String {
        if (checkBeans.isNotEmpty()) {
            val result: String = checkBeans
                .asSequence()
                .filter { o: ICheckBean -> Objects.nonNull(o) }
                .filter(ICheckBean::needTips)
                .map(ICheckBean::tip)
                .filter { str -> StrUtil.isNotBlank(str) }
                .joinToString(",")
            if (result.isNotBlank()) {
                return (getStartStr()
                        + result
                        + getEndStr()
                        )
            }
        }
        return ""
    }
}
